﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class ThermometerForm : ItemFormTemplate
    {
        public ThermometerForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\ThermometerForm\\ThermometerForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.MaxValue = 100;
            this.demo_control.MinValue = 0;
            this.demo_control.Value = 30;
            this.demo_control.Pipe.Diameter = 10;
            this.demo_control.Pipe.CosAngle = 50;
            this.demo_control.Mark.MainFrequency = 10;
            this.demo_control.Mark.Visible=true;
            this.demo_control.Mark.Alignment = ThermometerMarkAlignment.Left;
            this.demo_control.Mark.MainLineTextVisible = true;
            this.demo_control.Mark.MinorAmount = 1;

            this.maxValue_label.Text = this.demo_control.MaxValue.ToString();
            this.maxValue_trackBarPlus.Value = (float)this.demo_control.MaxValue;
            this.maxValue_trackBarPlus.ValueChanged += MaxValue_trackBarPlus_ValueChanged;

            this.minValue_label.Text = this.demo_control.MinValue.ToString();
            this.minValue_trackBarPlus.Value = (float)this.demo_control.MinValue;
            this.minValue_trackBarPlus.ValueChanged += this.MinValue_trackBarPlus_ValueChanged;

            this.value_label.Text = this.demo_control.Value.ToString();
            this.value_trackBarPlus.Value = (float)this.demo_control.Value;
            this.value_trackBarPlus.ValueChanged += this.Value_trackBarPlus_ValueChanged;

            this.pipeDiameter_label.Text = this.demo_control.Pipe.Diameter.ToString();
            this.pipeDiameter_trackBarPlus.Value = (float)this.demo_control.Pipe.Diameter;
            this.pipeDiameter_trackBarPlus.ValueChanged += this.Pipe_Diameter_trackBarPlus_ValueChanged;

            this.pipeCosAngle_label.Text = this.demo_control.Pipe.CosAngle.ToString();
            this.pipeCosAngle_trackBarPlus.Value = (float)this.demo_control.Pipe.CosAngle;
            this.pipeCosAngle_trackBarPlus.ValueChanged += this.Pipe_CosAngle_trackBarPlus_ValueChanged;

            this.markMainFrequency_label.Text = this.demo_control.Mark.MainFrequency.ToString();
            this.markMainFrequency_trackBarPlus.Value = (float)this.demo_control.Mark.MainFrequency;
            this.markMainFrequency_trackBarPlus.ValueChanged += this.Mark_MainFrequency_trackBarPlus_ValueChanged;

            this.markVisible_toggleSwitch.IsOn = this.demo_control.Mark.Visible;
            this.markVisible_toggleSwitch.Toggled += this.Mark_Visible_toggleSwitch_Toggled;

            this.markAlignment_dropDownListPlus.Multiple = false;
            this.markAlignment_dropDownListPlus.BindEnumList<ThermometerMarkAlignment>(this.demo_control.Mark.Alignment);
            this.markAlignment_dropDownListPlus.SelectedItemsChanged += this.Mark_Alignment_dropDownListPlus_SelectedItemsChanged;

            this.markMainLineTextVisible_toggleSwitch.IsOn = this.demo_control.Mark.MainLineTextVisible;
            this.markMainLineTextVisible_toggleSwitch.Toggled += this.Mark_MainLineTextVisible_toggleSwitch_Toggled;

            this.markMinorCount_label.Text = this.demo_control.Mark.MinorAmount.ToString();
            this.markMinorCount_trackBarPlus.Value = (float)this.demo_control.Mark.MinorAmount;
            this.markMinorCount_trackBarPlus.ValueChanged += this.Mark_MinorAmount_trackBarPlus_ValueChanged; 

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void MaxValue_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.MaxValue = control.Value;
            this.maxValue_label.Text = this.demo_control.MaxValue.ToString();
            this.minValue_label.Text = this.demo_control.MinValue.ToString();
            this.value_label.Text = this.demo_control.Value.ToString();
        }

        private void MinValue_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.MinValue = control.Value;
            this.maxValue_label.Text = this.demo_control.MaxValue.ToString();
            this.minValue_label.Text = this.demo_control.MinValue.ToString();
            this.value_label.Text = this.demo_control.Value.ToString();
        }

        private void Value_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.Value = control.Value;
            this.maxValue_label.Text = this.demo_control.MaxValue.ToString();
            this.minValue_label.Text = this.demo_control.MinValue.ToString();
            this.value_label.Text = this.demo_control.Value.ToString();
        }

        private void Pipe_Diameter_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.Pipe.Diameter = (int)control.Value;
            this.pipeDiameter_label.Text = this.demo_control.Pipe.Diameter.ToString();
        }

        private void Pipe_CosAngle_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.Pipe.CosAngle = (int)control.Value;
            this.pipeCosAngle_label.Text = this.demo_control.Pipe.CosAngle.ToString();
        }

        private void Mark_MainFrequency_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.Mark.MainFrequency = control.Value;
            this.markMainFrequency_label.Text = this.demo_control.Mark.MainFrequency.ToString();
        }

        private void Mark_Visible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.Mark.Visible = control.IsOn;
        }

        private void Mark_Alignment_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.Mark.Alignment = (ThermometerMarkAlignment)control.SelectedItem.Tag;
        }

        private void Mark_MainLineTextVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.Mark.MainLineTextVisible = control.IsOn;
        }

        private void Mark_MinorAmount_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.Mark.MinorAmount =(int) control.Value;
            this.markMinorCount_label.Text = this.demo_control.Mark.MinorAmount.ToString(); 
        }

        #endregion

    }
}
